package com.effectivcrm.domain

import org.springframework.data.annotation.CreatedBy
import org.springframework.data.annotation.CreatedDate
import org.springframework.data.annotation.Id
import org.springframework.data.annotation.LastModifiedBy
import org.springframework.data.annotation.LastModifiedDate
import org.springframework.data.annotation.Version

import com.fasterxml.jackson.annotation.JsonAnyGetter
import com.fasterxml.jackson.annotation.JsonAnySetter;


class BaseDocument {
	
	@Id
	String id;

	@Version
	Long version;

	@CreatedDate
	Date createdDate;

	@LastModifiedDate
	Date lastModifiedDate;


	@CreatedBy
	User createdBy;

	
	@LastModifiedBy
	User lastModifiedBy;
	
	boolean deleted;
	
	
	def dynamicProperties = [:]
	//setter
	def propertyMissing(String name, value) { dynamicProperties[name] = value }
	//getter
	def propertyMissing(String name) { dynamicProperties= [name] }
	
	
	@JsonAnySetter
	void setUnknown(String key, Object value) {
	  println "#### handling unknown field key = " + key + " value = " + value;
	  
	  propertyMissing(key, value);
	}
	
	@JsonAnyGetter
	Object getUnknown(String key) {
	  println "#### handling unknown field key = " + key ;
	  
	  return propertyMissing(key);
	}
}
